home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / cool / cool.lha / ice / pisces / touch / touch.c < prev   
Encoding:
C/C++ Source or Header  |  1991-09-04  |  956 b   |  42 lines

  1. /*
  2. //
  3. // Copyright (C) 1991 Texas Instruments Incorporated.
  4. //
  5. // Permission is granted to any individual or institution to use, copy, modify,
  6. // and distribute this software, provided that this complete copyright and
  7. // permission notice is maintained, intact, in all copies and supporting
  8. // documentation.
  9. //
  10. // Texas Instruments Incorporated provides this software "as is" without
  11. // express or implied warranty.
  12. //
  13.  * OS/2 doesn't have a touch command, so we gotta write one ...
  14.  */
  15. #include <stdio.h>
  16.  
  17. void main(argc, argv)
  18. int        argc;
  19. char        **argv;
  20. {
  21.   if (argc > 1) {    
  22.     if (freopen(argv[1], "a", stdin) == NULL) {
  23.       fprintf(stderr,"Can't create %s\n",argv[1]);
  24.       exit(1);
  25.     } else {
  26.       char c = 0;
  27.       if (ftell(stdin) != 0) {
  28.     rewind(stdin);
  29.     c = fgetc(stdin);
  30.     rewind(stdin);
  31.     fputc(c, stdin);
  32.       } else {
  33.     fputc(c, stdin);
  34.     fclose(stdin);
  35.     freopen(argv[1], "w", stdin);
  36.       }
  37.       fclose(stdin);
  38.     }
  39.   }
  40.   exit(0);
  41. }
  42.